clear all
set more off

* general path
* Here put the path of your files.
global chemin "HERE indicated path to the main folder"
cd "$chemin\data"

* you must have in this file a subfile for data called data. In this subfile data, have a subsubfile called input.

* Data on family planning aid from IHME data base.
	* you can download the data here : https://ghdx.healthdata.org/record/ihme-data/development-assistance-health-database-1990-2020

* data cleaning provided by IHME
use "$chemin\data\input\IHME_DAH_DATABASE_1990_2020_Y2021M09D22.dta", clear
	drop if elim_ch == 1 /* read readme IHME for explanation */
	drop elim_ch

*** additional data to deal with rounding in terms of funding. If funds < 500$ then variable = 0
* we decide to provide maximal case where all 0 represent 500$
	foreach i of varlist *dah* {
		gen `i'_boundmax = `i'
		replace `i'_boundmax = "0.5" if `i' == "-"
		gen `i'_boundm = `i'
		replace `i'_boundm = "0.05" if `i' == "-"
	}
	destring *dah*, replace force
	tempfile data
save data, replace

** Create EU aid because of IHME data EC is perceived as channel and not as donor
use data,clear
	keep if channel == "EC"
	collapse (sum) *dah*, by(year recipient* gbd_location_id- gbd_superregion_id)
	gen source = "European Union"
	gen channel = "BIL_EC"
save data2, replace
append using data
* we need now to delete the case where EC is the channel in order to avoird double-counting
	drop if channel == "EC"
save data, replace

use data,clear
* we exclude recipients who are not a specific country and donor who are not well identified of a group of donors.
	* we only keep global recipient for an aggregate version of the response.
	* just before we compute the share of fp aid which is deleted
	drop if recipient_c == "Administrative expenses"
	drop if recipient_c == "NA"
	drop if source == "Corporate_donations"
	drop if source == "Debt_repayments"
	drop if source == "Non_OECD_DAC_countries"
	drop if source == "Other_OECD_DAC_countries"
	drop if source == "Other"
	drop if source == "Private_other"
	drop if source == "Unallocable"
	keep year recipient_c source
	duplicates drop *, force
	fillin year recipient_c source
* we delete US aid because we need later to construct a specific variable for US aid 
	drop if source == "United_States"
	egen identifiant = group(recipient_c source)
	codebook recipient_c
save fill2 , replace

use data,clear
	drop if recipient_c == "Administrative expenses"
	drop if recipient_c == "NA"
	drop if source == "Corporate_donations"
	drop if source == "Debt_repayments"
	drop if source == "Non_OECD_DAC_countries"
	drop if source == "Other_OECD_DAC_countries"
	drop if source == "Other"
	drop if source == "Private_other"
	drop if source == "Unallocable"
	keep year source channel recipient* wb_* prelim_est rmh_* unalloc* *tb* *mal* *ncd* dah_20

* Create a dummy equal to 1 if aid is channelled through (international) NGO
	gen aid_ngo = (channel == "NGO" | channel =="INTLNGO")
* Create a dummy equal to 1 if aid is channelled through non bilateral implementing agencies (IAs)
	gen nonbil = (strpos(channel,"BIL")==0)

* Compute the amount of aid channelled by NGO, non bilateral IAs
	* NGO
		gen amount_ngo  		= aid_ngo * rmh_fp_dah_20
		gen amount_ngo_max  	= aid_ngo * rmh_fp_dah_20_boundmax
	* Non bilateral
		gen amount_nonbil 		= nonbil  * rmh_fp_dah_20
		gen amount_nonbil_max 	= nonbil  * rmh_fp_dah_20_boundmax
	* Total FP aid by recipient and year for the United_States
		bys recipient_c year : egen fpall  = total(rmh_fp_dah_20_boundmax) if source =="United_States"
	* FP aid channelled through NGOS by recipient and year for the United_States
		bys recipient_c year : egen vngo = total(amount_ngo_max) if source =="United_States"
	* FP aid channelled non bilaterally by recipient and year for the United_States
		bys recipient_c year : egen vnonbil = total(amount_nonbil_max) if source =="United_States"
	* FP by donors
	bys recipient_c source year : egen amount_donor  = total(rmh_fp_dah_20) 
	* non bilateral aid by donors
	bys recipient_c source year : egen v_donor = total(amount_nonbil) 
	gen sharenonbil_donor = v_donor /amount_donor
	replace sharenonbil_donor = 0 if amount_donor==0 & v_donor ==0
	* Share of US FP aid channelled by NGO by recipient/year
		gen sharengo = vngo / fpall
		replace sharengo = 0 if fpall==0 & vngo ==0
	* Share of US FP aid channelled by non bilateral agency by recipient/year
		gen sharenonbil = vnonbil / fpall
		replace sharenonbil = 0 if fpall==0 & vnonbil ==0
	* Compute by recipient average share of aid channelled by NGOs during Obama term
		bys recipient_country : egen share_NGOUS_Obama = mean(sharengo) if source =="United_States"  &  ((year >=2009 & year <=2016) )
		bys recipient_country year : gen usshare = sharengo
	* Compute by recipient average share of aid channelled by NGOs when the MCP is not active
		bys recipient_country : egen share_NGOUS_MCP = mean(sharengo) if source =="United_States"  & ((year >=2009 & year <=2016) | (year >=2021) | (year >= 1993 & year <=1994) | (year > 1995 & year <=1999))

collapse (sum) *rmh* unalloc* *tb* *mal* *ncd* amount_ngo dah_20 (mean) usshare share_NGOUS_Obama share_NGOUS_MCP sharengo sharenonbil sharenonbil_donor, by(year  source recipient_country wb*)
save a2, replace
* nb obs : 107,939
* Database including FP aid from all donors. and US aid in column
merge n:n year recipient_c source using fill2

gsort recipient_country -source share_NGOUS_MCP
bys recipient_country : replace share_NGOUS_MCP = share_NGOUS_MCP[_n-1] if share_NGOUS_MCP == . & share_NGOUS_MCP[_n-1] != .

gsort recipient_country -source share_NGOUS_Obama
bys recipient_country : replace share_NGOUS_Obama = share_NGOUS_Obama[_n-1] if share_NGOUS_Obama == . & share_NGOUS_Obama[_n-1] != .

gsort recipient_country -source sharenonbil
bys recipient_country : replace sharenonbil = sharenonbil[_n-1] if sharenonbil == . & sharenonbil[_n-1] != .

gsort recipient_country year -source sharengo
bys recipient_country year : replace sharengo = sharengo[_n-1] if sharengo == . & sharengo[_n-1] != .

sort recipient_country sharenonbil_donor
bys recipient_country : replace sharenonbil_donor = sharenonbil_donor[_n-1] if sharenonbil_donor == . & sharenonbil_donor[_n-1] != .


gsort recipient_country year -source usshare
bys recipient_country year : replace usshare = usshare[_n-1] if usshare == . & usshare[_n-1] != .


* For never US recipient of FP or DAH, share of NGO aid channelled through NGO is equal to 0.
replace  share_NGOUS_Obama = 0 if source == "United_States" & share_NGOUS_Obama == . & (rmh_fp_dah_20==0 | rmh_fp_dah_20 == . | dah_20==0 |dah_20 == .)
replace  share_NGOUS_MCP = 0 if source == "United_States" & share_NGOUS_MCP == . & (rmh_fp_dah_20==0 | rmh_fp_dah_20 == . | dah_20==0 |dah_20 == .)
* specific case of  Northern Mariana Islands --> 0 aid during non MCP --> share NGO == 0
replace  share_NGOUS_Obama = 0 if source == "United_States" & recipient_c == "Northern Mariana Islands"
replace  share_NGOUS_MCP = 0 if source == "United_States" & recipient_c == "Northern Mariana Islands"


gsort recipient_country -source share_NGOUS_MCP
bys recipient_country : replace share_NGOUS_MCP = share_NGOUS_MCP[_n-1] if share_NGOUS_MCP == . & share_NGOUS_MCP[_n-1] != .

gsort recipient_country -source  share_NGOUS_Obama
bys recipient_country : replace share_NGOUS_Obama = share_NGOUS_Obama[_n-1] if share_NGOUS_Obama == . & share_NGOUS_Obama[_n-1] != .

gsort recipient_country -source  sharenonbil
bys recipient_country : replace sharenonbil = sharenonbil[_n-1] if sharenonbil == . & sharenonbil[_n-1] != .

gsort recipient_country year -source sharengo
bys recipient_country year : replace sharengo = sharengo[_n-1] if sharengo == . & sharengo[_n-1] != .

gsort recipient_country year -source usshare
bys recipient_country year : replace usshare = usshare[_n-1] if usshare == . & usshare[_n-1] != .



* Creation of US funding for family planning
foreach i of varlist rmh* unalloc* *tb* *mal* *ncd* {
gen `i'_US = .
bys year recipient* : egen intermediaire = max(`i') if source == "United_States"
sort year recipient* intermediaire
by year recipient* : replace intermediaire = intermediaire[_n-1] if intermediaire == .
replace `i'_US = intermediaire
drop intermediaire
}

drop if source == "United_States"

foreach i of varlist *rmh* unalloc* share_NGO* usshare {
replace `i' = 0 if `i' == .
}
drop _m 
codebook recipient_c
save "$chemin\data\final_IHME22.dta", replace



* Creation of control variables
	* GDP pc 2010$
	* female life expectancy at birth
	* maternal mortality ratio (modeled)
	* Incidence of HIV
	* prevalence of HIV in 15-49yo
	* total population
	* poverty headcount ratio
* year from 1990 to 2019	
import excel "$chemin\data\input\Data_Extract_From_World_Development_Indicators.xlsx", sheet("Data") firstrow clear


preserve
keep if Series =="poverty"
reshape long YR, i(Country*) j(year)
* we mannually include data on poverty coming from http://mdgs.un.org/unsd/mdg/Data.aspx
rename YR poverty_r
replace poverty ="0" if CountryName == "Belarus" & year ==1993
replace poverty ="0" if CountryName == "Bulgaria" & year ==1992
replace poverty ="0" if CountryName == "Croatia" & year ==1998
replace poverty ="0" if CountryName == "Croatia" & year ==2004
replace poverty ="0" if CountryName == "Croatia" & year ==2008
replace poverty ="0" if CountryName == "Latvia" & year ==1993
replace poverty ="0" if CountryName == "Latvia" & year ==1995
replace poverty ="0" if CountryName == "Latvia" & year ==1998
replace poverty ="0" if CountryName == "Lithuania" & year ==1996
replace poverty ="0" if CountryName == "Montenegro" & year ==2009
replace poverty ="0" if CountryName == "Montenegro" & year ==2010
replace poverty ="0" if CountryName == "Poland" & year ==1992
replace poverty ="0" if CountryName == "Poland" & year ==1997
replace poverty ="0" if CountryName == "Poland" & year ==1998
replace poverty ="0" if CountryName == "Poland" & year ==2001
replace poverty ="0" if CountryName == "Romania" & year ==2004
replace poverty ="0" if CountryName == "Romania" & year ==2005
replace poverty ="0" if CountryName == "Serbia" & year ==2008
replace poverty ="0" if CountryName == "Seychelles" & year ==1999
replace poverty ="0" if CountryName == "Slovak Republic" & year ==1993
replace poverty ="0.1" if CountryName == "Croatia" & year ==2000
replace poverty ="0.1" if CountryName == "Croatia" & year ==2001
replace poverty ="0.1" if CountryName == "Estonia" & year ==1999
replace poverty ="0.1" if CountryName == "Lithuania" & year ==1998
replace poverty ="0.1" if CountryName == "Lithuania" & year ==2000
replace poverty ="0.1" if CountryName == "Lithuania" & year ==2003
replace poverty ="0.1" if CountryName == "Montenegro" & year ==2006
replace poverty ="0.1" if CountryName == "Montenegro" & year ==2008
replace poverty ="0.1" if CountryName == "Poland" & year ==1999
replace poverty ="0.1" if CountryName == "Poland" & year ==2000
replace poverty ="0.1" if CountryName == "Poland" & year ==2003
replace poverty ="0.1" if CountryName == "Serbia" & year ==2007
replace poverty ="0.1" if CountryName == "Serbia" & year ==2009
replace poverty ="0.1" if CountryName == "Serbia" & year ==2010
replace poverty ="0.2" if CountryName == "Bulgaria" & year ==1994
replace poverty ="0.2" if CountryName == "Croatia" & year ==1999
replace poverty ="0.2" if CountryName == "Lithuania" & year ==2002
replace poverty ="0.2" if CountryName == "Montenegro" & year ==2011
replace poverty ="0.2" if CountryName == "Slovak Republic" & year ==1997
replace poverty ="0.3" if CountryName == "Bulgaria" & year ==1997
replace poverty ="0.3" if CountryName == "Estonia" & year ==1996
replace poverty ="0.3" if CountryName == "Lithuania" & year ==2001
replace poverty ="0.3" if CountryName == "Montenegro" & year ==2005
replace poverty ="0.3" if CountryName == "Serbia" & year ==2002
replace poverty ="0.3" if CountryName == "Serbia" & year ==2003
replace poverty ="0.3" if CountryName == "Serbia" & year ==2006
replace poverty ="0.3" if CountryName == "Seychelles" & year ==2006
replace poverty ="0.4" if CountryName == "Belarus" & year ==1995
replace poverty ="0.4" if CountryName == "Latvia" & year ==1996
replace poverty ="0.4" if CountryName == "Latvia" & year ==2002
replace poverty ="0.4" if CountryName == "Montenegro" & year ==2007
replace poverty ="0.4" if CountryName == "Romania" & year ==1992
replace poverty ="0.4" if CountryName == "Serbia" & year ==2004
replace poverty ="0.6" if CountryName == "Bulgaria" & year ==2003
replace poverty ="0.6" if CountryName == "Estonia" & year ==2001
replace poverty ="0.6" if CountryName == "Estonia" & year ==2002
replace poverty ="0.6" if CountryName == "Latvia" & year ==1997
replace poverty ="0.6" if CountryName == "Serbia" & year ==2005
replace poverty ="0.8" if CountryName == "Bulgaria" & year ==1995
replace poverty ="0.8" if CountryName == "Estonia" & year ==1994
replace poverty ="1.4" if CountryName == "Poland" & year ==1995
replace poverty ="1.6" if CountryName == "Romania" & year ==2003
replace poverty ="1.7" if CountryName == "Romania" & year ==1998
replace poverty ="2.1" if CountryName == "Bulgaria" & year ==2001
replace poverty ="2.2" if CountryName == "Lithuania" & year ==1993
replace poverty ="2.5" if CountryName == "Romania" & year ==2001
replace poverty ="2.6" if CountryName == "Romania" & year ==2002
replace poverty ="2.9" if CountryName == "Romania" & year ==1999
replace poverty ="4.2" if CountryName == "Kazakhstan" & year ==1993
replace poverty ="5" if CountryName == "Romania" & year ==1994
replace poverty ="5.2" if CountryName == "Bolivia" & year ==1990
replace poverty ="8.2" if CountryName == "Colombia" & year ==1991
replace poverty ="9.8" if CountryName == "Peru" & year ==1994
replace poverty ="10.1" if CountryName == "Cambodia" & year ==2010
replace poverty ="11.3" if CountryName == "Cambodia" & year ==2009
replace poverty ="12.9" if CountryName == "Cambodia" & year ==2008
replace poverty ="16.8" if CountryName == "Armenia" & year ==1998
replace poverty ="17.5" if CountryName == "Armenia" & year ==1996
replace poverty ="18.6" if CountryName == "Kyrgyz Republic" & year ==1993
replace poverty ="20.9" if CountryName == "Cambodia" & year ==2007
replace poverty ="23.7" if CountryName == "Philippines" & year ==1997
replace poverty ="25.6" if CountryName == "Maldives" & year ==1998
replace poverty ="30.5" if CountryName == "Philippines" & year ==1994
replace poverty ="30.8" if CountryName == "Cambodia" & year ==2006
replace poverty ="31.2" if CountryName == "Micronesia, Fed. Sts." & year ==2000
replace poverty ="32.8" if CountryName == "Cambodia" & year ==2004
replace poverty ="33.2" if CountryName == "Philippines" & year ==1991
replace poverty ="44.5" if CountryName == "Cambodia" & year ==1994
replace poverty ="49.1" if CountryName == "Namibia" & year ==1993
replace poverty ="61.7" if CountryName == "Haiti" & year ==2001
replace poverty ="61.9" if CountryName == "Chad" & year ==2002
replace poverty ="63.5" if CountryName == "Turkmenistan" & year ==1994

replace poverty = "0.1" if poverty =="0"
save temp, replace
restore

preserve
keep if Series =="GDPpcUS2010"
reshape long YR, i(Country*) j(year)
rename YR GDPpc_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
keep if Series =="adofertility"
reshape long YR, i(Country*) j(year)
rename YR adofertility_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
keep if Series =="fertility"
reshape long YR, i(Country*) j(year)
rename YR fertility_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
keep if Series =="incidenceHIV_r"
reshape long YR, i(Country*) j(year)
* we manually include data on incidenceHIV coming from http://mdgs.un.org/unsd/mdg/Data.aspx when data where missing before
rename YR incidenceHIV_r
replace incidenceHIV_r ="0.00" if CountryName == "Bangladesh" & year ==2013
replace incidenceHIV_r ="0.00" if CountryName == "Belize" & year ==1990
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1990
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1991
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1992
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1993
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1994
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1995
replace incidenceHIV_r ="0.00" if CountryName == "Georgia" & year ==1996
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1990
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1991
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1992
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1993
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1994
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1995
replace incidenceHIV_r ="0.00" if CountryName == "Indonesia" & year ==1996
replace incidenceHIV_r ="0.00" if CountryName == "Macedonia" & year ==2013
replace incidenceHIV_r ="0.00" if CountryName == "Maldives" & year ==2013
replace incidenceHIV_r ="0.00" if CountryName == "Sao Tome and Principe" & year ==2010
replace incidenceHIV_r ="0.00" if CountryName == "Sao Tome and Principe" & year ==2011
replace incidenceHIV_r ="0.00" if CountryName == "Sao Tome and Principe" & year ==2012
replace incidenceHIV_r ="0.00" if CountryName == "Sao Tome and Principe" & year ==2013
replace incidenceHIV_r ="0.01" if CountryName == "Belize" & year ==1991
replace incidenceHIV_r ="0.01" if CountryName == "Belize" & year ==1992
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==1997
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==1998
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==1999
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==2000
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==2001
replace incidenceHIV_r ="0.01" if CountryName == "Georgia" & year ==2002
replace incidenceHIV_r ="0.01" if CountryName == "India" & year ==1990
replace incidenceHIV_r ="0.01" if CountryName == "India" & year ==1991
replace incidenceHIV_r ="0.01" if CountryName == "Indonesia" & year ==1997
replace incidenceHIV_r ="0.01" if CountryName == "Indonesia" & year ==1998
replace incidenceHIV_r ="0.01" if CountryName == "Indonesia" & year ==1999
replace incidenceHIV_r ="0.01" if CountryName == "Mexico" & year ==1990
replace incidenceHIV_r ="0.01" if CountryName == "Mexico" & year ==1991
replace incidenceHIV_r ="0.01" if CountryName == "Mexico" & year ==1992
replace incidenceHIV_r ="0.01" if CountryName == "Mexico" & year ==2013
replace incidenceHIV_r ="0.01" if CountryName == "Sao Tome and Principe" & year ==2009
replace incidenceHIV_r ="0.02" if CountryName == "Georgia" & year ==2003
replace incidenceHIV_r ="0.02" if CountryName == "Georgia" & year ==2004
replace incidenceHIV_r ="0.02" if CountryName == "Georgia" & year ==2005
replace incidenceHIV_r ="0.02" if CountryName == "Georgia" & year ==2006
replace incidenceHIV_r ="0.02" if CountryName == "Georgia" & year ==2007
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==1992
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2005
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2006
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2007
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2008
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2009
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2010
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2011
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2012
replace incidenceHIV_r ="0.02" if CountryName == "India" & year ==2013
replace incidenceHIV_r ="0.02" if CountryName == "Indonesia" & year ==2000
replace incidenceHIV_r ="0.02" if CountryName == "Indonesia" & year ==2001
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1993
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1994
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1995
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1996
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1997
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1998
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==1999
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2000
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2001
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2002
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2003
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2004
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2005
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2006
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2007
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2008
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2009
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2010
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2011
replace incidenceHIV_r ="0.02" if CountryName == "Mexico" & year ==2012
replace incidenceHIV_r ="0.03" if CountryName == "Belize" & year ==1993
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2008
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2009
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2010
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2011
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2012
replace incidenceHIV_r ="0.03" if CountryName == "Georgia" & year ==2013
replace incidenceHIV_r ="0.03" if CountryName == "India" & year ==2003
replace incidenceHIV_r ="0.03" if CountryName == "India" & year ==2004
replace incidenceHIV_r ="0.03" if CountryName == "Indonesia" & year ==2002
replace incidenceHIV_r ="0.03" if CountryName == "Mali" & year ==2012
replace incidenceHIV_r ="0.03" if CountryName == "Mali" & year ==2013
replace incidenceHIV_r ="0.03" if CountryName == "Sao Tome and Principe" & year ==1990
replace incidenceHIV_r ="0.03" if CountryName == "Sao Tome and Principe" & year ==2008
replace incidenceHIV_r ="0.04" if CountryName == "India" & year ==1993
replace incidenceHIV_r ="0.04" if CountryName == "India" & year ==2002
replace incidenceHIV_r ="0.04" if CountryName == "Indonesia" & year ==2003
replace incidenceHIV_r ="0.04" if CountryName == "Indonesia" & year ==2004
replace incidenceHIV_r ="0.04" if CountryName == "Indonesia" & year ==2005
replace incidenceHIV_r ="0.04" if CountryName == "Mali" & year ==2011
replace incidenceHIV_r ="0.04" if CountryName == "Panama" & year ==1992
replace incidenceHIV_r ="0.04" if CountryName == "Sao Tome and Principe" & year ==1991
replace incidenceHIV_r ="0.04" if CountryName == "Uruguay" & year ==2013
replace incidenceHIV_r ="0.05" if CountryName == "India" & year ==1994
replace incidenceHIV_r ="0.05" if CountryName == "India" & year ==2000
replace incidenceHIV_r ="0.05" if CountryName == "India" & year ==2001
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2006
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2007
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2008
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2009
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2010
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2011
replace incidenceHIV_r ="0.05" if CountryName == "Indonesia" & year ==2012
replace incidenceHIV_r ="0.05" if CountryName == "Mali" & year ==2010
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==1993
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==1994
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==1995
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==1999
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2000
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2001
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2002
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2003
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2004
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2005
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2006
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2007
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2008
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2009
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2010
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2011
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2012
replace incidenceHIV_r ="0.05" if CountryName == "Panama" & year ==2013
replace incidenceHIV_r ="0.05" if CountryName == "Sao Tome and Principe" & year ==2007
replace incidenceHIV_r ="0.06" if CountryName == "Belize" & year ==1994
replace incidenceHIV_r ="0.06" if CountryName == "India" & year ==1995
replace incidenceHIV_r ="0.06" if CountryName == "India" & year ==1999
replace incidenceHIV_r ="0.06" if CountryName == "Indonesia" & year ==2013
replace incidenceHIV_r ="0.06" if CountryName == "Mali" & year ==2009
replace incidenceHIV_r ="0.06" if CountryName == "Panama" & year ==1996
replace incidenceHIV_r ="0.06" if CountryName == "Panama" & year ==1997
replace incidenceHIV_r ="0.06" if CountryName == "Panama" & year ==1998
replace incidenceHIV_r ="0.06" if CountryName == "Sao Tome and Principe" & year ==1992
replace incidenceHIV_r ="0.07" if CountryName == "India" & year ==1996
replace incidenceHIV_r ="0.07" if CountryName == "India" & year ==1997
replace incidenceHIV_r ="0.07" if CountryName == "India" & year ==1998
replace incidenceHIV_r ="0.07" if CountryName == "Mali" & year ==2007
replace incidenceHIV_r ="0.07" if CountryName == "Mali" & year ==2008
replace incidenceHIV_r ="0.08" if CountryName == "Mali" & year ==2006
replace incidenceHIV_r ="0.08" if CountryName == "Panama" & year ==1991
replace incidenceHIV_r ="0.08" if CountryName == "Sao Tome and Principe" & year ==1993
replace incidenceHIV_r ="0.08" if CountryName == "Sao Tome and Principe" & year ==2006
replace incidenceHIV_r ="0.09" if CountryName == "Belize" & year ==2010
replace incidenceHIV_r ="0.09" if CountryName == "Belize" & year ==2011
replace incidenceHIV_r ="0.09" if CountryName == "Belize" & year ==2012
replace incidenceHIV_r ="0.09" if CountryName == "Belize" & year ==2013
replace incidenceHIV_r ="0.09" if CountryName == "Panama" & year ==1990
replace incidenceHIV_r ="0.10" if CountryName == "Belize" & year ==2006
replace incidenceHIV_r ="0.10" if CountryName == "Mali" & year ==2005
replace incidenceHIV_r ="0.10" if CountryName == "Sao Tome and Principe" & year ==1994
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2003
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2004
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2005
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2007
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2008
replace incidenceHIV_r ="0.11" if CountryName == "Belize" & year ==2009
replace incidenceHIV_r ="0.11" if CountryName == "Mali" & year ==2004
replace incidenceHIV_r ="0.12" if CountryName == "Belize" & year ==1995
replace incidenceHIV_r ="0.12" if CountryName == "Mali" & year ==1990
replace incidenceHIV_r ="0.12" if CountryName == "Sao Tome and Principe" & year ==2005
replace incidenceHIV_r ="0.13" if CountryName == "Mali" & year ==2003
replace incidenceHIV_r ="0.13" if CountryName == "Sao Tome and Principe" & year ==1995
replace incidenceHIV_r ="0.14" if CountryName == "Belize" & year ==2002
replace incidenceHIV_r ="0.15" if CountryName == "Mali" & year ==2002
replace incidenceHIV_r ="0.15" if CountryName == "Sao Tome and Principe" & year ==1996
replace incidenceHIV_r ="0.16" if CountryName == "Mali" & year ==1991
replace incidenceHIV_r ="0.16" if CountryName == "Mali" & year ==2001
replace incidenceHIV_r ="0.16" if CountryName == "Sao Tome and Principe" & year ==2004
replace incidenceHIV_r ="0.18" if CountryName == "Mali" & year ==2000
replace incidenceHIV_r ="0.18" if CountryName == "Sao Tome and Principe" & year ==1997
replace incidenceHIV_r ="0.19" if CountryName == "Sao Tome and Principe" & year ==2003
replace incidenceHIV_r ="0.20" if CountryName == "Mali" & year ==1992
replace incidenceHIV_r ="0.21" if CountryName == "Mali" & year ==1999
replace incidenceHIV_r ="0.21" if CountryName == "Sao Tome and Principe" & year ==1998
replace incidenceHIV_r ="0.22" if CountryName == "Belize" & year ==2001
replace incidenceHIV_r ="0.22" if CountryName == "Sao Tome and Principe" & year ==1999
replace incidenceHIV_r ="0.22" if CountryName == "Sao Tome and Principe" & year ==2002
replace incidenceHIV_r ="0.23" if CountryName == "Belize" & year ==1996
replace incidenceHIV_r ="0.23" if CountryName == "Mali" & year ==1993
replace incidenceHIV_r ="0.23" if CountryName == "Mali" & year ==1998
replace incidenceHIV_r ="0.24" if CountryName == "Sao Tome and Principe" & year ==2000
replace incidenceHIV_r ="0.24" if CountryName == "Sao Tome and Principe" & year ==2001
replace incidenceHIV_r ="0.25" if CountryName == "Mali" & year ==1997
replace incidenceHIV_r ="0.26" if CountryName == "Mali" & year ==1994
replace incidenceHIV_r ="0.27" if CountryName == "Mali" & year ==1995
replace incidenceHIV_r ="0.27" if CountryName == "Mali" & year ==1996
replace incidenceHIV_r ="0.35" if CountryName == "Belize" & year ==2000
replace incidenceHIV_r ="0.38" if CountryName == "Belize" & year ==1997
replace incidenceHIV_r ="0.47" if CountryName == "Belize" & year ==1999
replace incidenceHIV_r ="0.48" if CountryName == "Belize" & year ==1998
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
keep if Series =="life_expectency_fe"
reshape long YR, i(Country*) j(year)
rename YR life_expectencyfe_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore



preserve
keep if Series =="population"
reshape long YR, i(Country*) j(year)
rename YR pop_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
keep if Series =="prevalence_HIV_1549"
reshape long YR, i(Country*) j(year)
* we manually include data on HIV incidence coming from http://mdgs.un.org/unsd/mdg/Data.aspx

rename YR HIV1549_r
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1990
replace HIV1549_r ="0.00" if CountryName == "Belize" & year ==1990
replace HIV1549_r ="0.00" if CountryName == "Indonesia" & year ==1990
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1991
replace HIV1549_r ="0.00" if CountryName == "Indonesia" & year ==1991
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1992
replace HIV1549_r ="0.00" if CountryName == "Indonesia" & year ==1992
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1993
replace HIV1549_r ="0.00" if CountryName == "Indonesia" & year ==1993
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1994
replace HIV1549_r ="0.00" if CountryName == "Indonesia" & year ==1994
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1995
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1996
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1997
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1998
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==1999
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==2000
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==2001
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==2002
replace HIV1549_r ="0.00" if CountryName == "Bangladesh" & year ==2003
replace HIV1549_r ="0.01" if CountryName == "Bhutan" & year ==1990
replace HIV1549_r ="0.01" if CountryName == "Estonia" & year ==1990
replace HIV1549_r ="0.01" if CountryName == "Belize" & year ==1991
replace HIV1549_r ="0.01" if CountryName == "Bhutan" & year ==1991
replace HIV1549_r ="0.01" if CountryName == "Bhutan" & year ==1992
replace HIV1549_r ="0.01" if CountryName == "Indonesia" & year ==1995
replace HIV1549_r ="0.01" if CountryName == "Indonesia" & year ==1996
replace HIV1549_r ="0.01" if CountryName == "Indonesia" & year ==1997
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2004
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2005
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2006
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2007
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2008
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2009
replace HIV1549_r ="0.01" if CountryName == "Maldives" & year ==2009
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2010
replace HIV1549_r ="0.01" if CountryName == "Maldives" & year ==2010
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2011
replace HIV1549_r ="0.01" if CountryName == "Maldives" & year ==2011
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2012
replace HIV1549_r ="0.01" if CountryName == "Maldives" & year ==2012
replace HIV1549_r ="0.01" if CountryName == "Bangladesh" & year ==2013
replace HIV1549_r ="0.01" if CountryName == "Maldives" & year ==2013
replace HIV1549_r ="0.02" if CountryName == "India" & year ==1990
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1990
replace HIV1549_r ="0.02" if CountryName == "Estonia" & year ==1991
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1991
replace HIV1549_r ="0.02" if CountryName == "Belize" & year ==1992
replace HIV1549_r ="0.02" if CountryName == "Estonia" & year ==1992
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1992
replace HIV1549_r ="0.02" if CountryName == "Bhutan" & year ==1993
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1993
replace HIV1549_r ="0.02" if CountryName == "Bhutan" & year ==1994
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1994
replace HIV1549_r ="0.02" if CountryName == "Bhutan" & year ==1995
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1995
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1996
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1997
replace HIV1549_r ="0.02" if CountryName == "Indonesia" & year ==1998
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1998
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==1999
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2000
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2001
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2002
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2003
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2004
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2005
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2006
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2007
replace HIV1549_r ="0.02" if CountryName == "Maldives" & year ==2008
replace HIV1549_r ="0.03" if CountryName == "India" & year ==1991
replace HIV1549_r ="0.03" if CountryName == "Bhutan" & year ==1996
replace HIV1549_r ="0.03" if CountryName == "Bhutan" & year ==1997
replace HIV1549_r ="0.03" if CountryName == "Bhutan" & year ==1998
replace HIV1549_r ="0.03" if CountryName == "Indonesia" & year ==1999
replace HIV1549_r ="0.04" if CountryName == "Belize" & year ==1993
replace HIV1549_r ="0.04" if CountryName == "Estonia" & year ==1993
replace HIV1549_r ="0.04" if CountryName == "Bhutan" & year ==1999
replace HIV1549_r ="0.04" if CountryName == "Bhutan" & year ==2000
replace HIV1549_r ="0.05" if CountryName == "Estonia" & year ==1994
replace HIV1549_r ="0.05" if CountryName == "Indonesia" & year ==2000
replace HIV1549_r ="0.05" if CountryName == "Bhutan" & year ==2001
replace HIV1549_r ="0.06" if CountryName == "Uruguay" & year ==1990
replace HIV1549_r ="0.06" if CountryName == "India" & year ==1992
replace HIV1549_r ="0.06" if CountryName == "Bhutan" & year ==2002
replace HIV1549_r ="0.06" if CountryName == "Bhutan" & year ==2003
replace HIV1549_r ="0.07" if CountryName == "Sao Tome and Principe" & year ==1990
replace HIV1549_r ="0.07" if CountryName == "Indonesia" & year ==2001
replace HIV1549_r ="0.07" if CountryName == "Bhutan" & year ==2004
replace HIV1549_r ="0.08" if CountryName == "Estonia" & year ==1995
replace HIV1549_r ="0.08" if CountryName == "Bhutan" & year ==2005
replace HIV1549_r ="0.08" if CountryName == "Bhutan" & year ==2006
replace HIV1549_r ="0.09" if CountryName == "Uruguay" & year ==1991
replace HIV1549_r ="0.09" if CountryName == "India" & year ==1993
replace HIV1549_r ="0.09" if CountryName == "Bhutan" & year ==2007
replace HIV1549_r ="0.10" if CountryName == "Mexico" & year ==1990
replace HIV1549_r ="0.10" if CountryName == "Sao Tome and Principe" & year ==1991
replace HIV1549_r ="0.10" if CountryName == "Belize" & year ==1994
replace HIV1549_r ="0.10" if CountryName == "Indonesia" & year ==2002
replace HIV1549_r ="0.10" if CountryName == "Bhutan" & year ==2008
replace HIV1549_r ="0.10" if CountryName == "Bhutan" & year ==2009
replace HIV1549_r ="0.11" if CountryName == "Mexico" & year ==1991
replace HIV1549_r ="0.11" if CountryName == "Mexico" & year ==1992
replace HIV1549_r ="0.11" if CountryName == "Bhutan" & year ==2010
replace HIV1549_r ="0.12" if CountryName == "Uruguay" & year ==1992
replace HIV1549_r ="0.12" if CountryName == "Mexico" & year ==1993
replace HIV1549_r ="0.12" if CountryName == "Estonia" & year ==1996
replace HIV1549_r ="0.12" if CountryName == "Bhutan" & year ==2011
replace HIV1549_r ="0.12" if CountryName == "Bhutan" & year ==2012
replace HIV1549_r ="0.13" if CountryName == "Uruguay" & year ==1993
replace HIV1549_r ="0.13" if CountryName == "India" & year ==1994
replace HIV1549_r ="0.13" if CountryName == "Mexico" & year ==1994
replace HIV1549_r ="0.13" if CountryName == "Mexico" & year ==1995
replace HIV1549_r ="0.13" if CountryName == "Indonesia" & year ==2003
replace HIV1549_r ="0.13" if CountryName == "Bhutan" & year ==2013
replace HIV1549_r ="0.14" if CountryName == "Mexico" & year ==1996
replace HIV1549_r ="0.15" if CountryName == "Sao Tome and Principe" & year ==1992
replace HIV1549_r ="0.15" if CountryName == "Uruguay" & year ==1994
replace HIV1549_r ="0.15" if CountryName == "Mexico" & year ==1997
replace HIV1549_r ="0.16" if CountryName == "Mexico" & year ==1998
replace HIV1549_r ="0.16" if CountryName == "Indonesia" & year ==2004
replace HIV1549_r ="0.17" if CountryName == "Estonia" & year ==1997
replace HIV1549_r ="0.17" if CountryName == "Mexico" & year ==1999
replace HIV1549_r ="0.18" if CountryName == "Uruguay" & year ==1995
replace HIV1549_r ="0.18" if CountryName == "Mexico" & year ==2000
replace HIV1549_r ="0.19" if CountryName == "India" & year ==1995
replace HIV1549_r ="0.19" if CountryName == "Mexico" & year ==2001
replace HIV1549_r ="0.19" if CountryName == "Mexico" & year ==2002
replace HIV1549_r ="0.20" if CountryName == "Belize" & year ==1995
replace HIV1549_r ="0.20" if CountryName == "Mexico" & year ==2003
replace HIV1549_r ="0.20" if CountryName == "Indonesia" & year ==2005
replace HIV1549_r ="0.21" if CountryName == "Sao Tome and Principe" & year ==1993
replace HIV1549_r ="0.21" if CountryName == "Mexico" & year ==2004
replace HIV1549_r ="0.22" if CountryName == "Uruguay" & year ==1996
replace HIV1549_r ="0.22" if CountryName == "Mexico" & year ==2005
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2006
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2007
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2008
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2009
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2010
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2011
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2012
replace HIV1549_r ="0.23" if CountryName == "Mexico" & year ==2013
replace HIV1549_r ="0.24" if CountryName == "India" & year ==1996
replace HIV1549_r ="0.24" if CountryName == "Indonesia" & year ==2006
replace HIV1549_r ="0.25" if CountryName == "Estonia" & year ==1998
replace HIV1549_r ="0.26" if CountryName == "Uruguay" & year ==1997
replace HIV1549_r ="0.26" if CountryName == "India" & year ==2013
replace HIV1549_r ="0.27" if CountryName == "Indonesia" & year ==2007
replace HIV1549_r ="0.27" if CountryName == "India" & year ==2011
replace HIV1549_r ="0.27" if CountryName == "India" & year ==2012
replace HIV1549_r ="0.28" if CountryName == "India" & year ==2010
replace HIV1549_r ="0.29" if CountryName == "Sao Tome and Principe" & year ==1994
replace HIV1549_r ="0.30" if CountryName == "India" & year ==1997
replace HIV1549_r ="0.30" if CountryName == "India" & year ==2009
replace HIV1549_r ="0.31" if CountryName == "Uruguay" & year ==1998
replace HIV1549_r ="0.31" if CountryName == "India" & year ==2008
replace HIV1549_r ="0.31" if CountryName == "Indonesia" & year ==2008
replace HIV1549_r ="0.33" if CountryName == "India" & year ==2007
replace HIV1549_r ="0.34" if CountryName == "India" & year ==1998
replace HIV1549_r ="0.34" if CountryName == "Estonia" & year ==1999
replace HIV1549_r ="0.34" if CountryName == "Indonesia" & year ==2009
replace HIV1549_r ="0.35" if CountryName == "India" & year ==2006
replace HIV1549_r ="0.37" if CountryName == "Uruguay" & year ==1999
replace HIV1549_r ="0.37" if CountryName == "India" & year ==2005
replace HIV1549_r ="0.37" if CountryName == "Indonesia" & year ==2010
replace HIV1549_r ="0.38" if CountryName == "India" & year ==1999
replace HIV1549_r ="0.39" if CountryName == "Sao Tome and Principe" & year ==1995
replace HIV1549_r ="0.39" if CountryName == "India" & year ==2004
replace HIV1549_r ="0.40" if CountryName == "India" & year ==2000
replace HIV1549_r ="0.40" if CountryName == "India" & year ==2003
replace HIV1549_r ="0.40" if CountryName == "Indonesia" & year ==2011
replace HIV1549_r ="0.41" if CountryName == "Belize" & year ==1996
replace HIV1549_r ="0.41" if CountryName == "India" & year ==2001
replace HIV1549_r ="0.41" if CountryName == "India" & year ==2002
replace HIV1549_r ="0.43" if CountryName == "Indonesia" & year ==2012
replace HIV1549_r ="0.44" if CountryName == "Uruguay" & year ==2000
replace HIV1549_r ="0.46" if CountryName == "Estonia" & year ==2000
replace HIV1549_r ="0.46" if CountryName == "Indonesia" & year ==2013
replace HIV1549_r ="0.50" if CountryName == "Uruguay" & year ==2001
replace HIV1549_r ="0.51" if CountryName == "Sao Tome and Principe" & year ==1996
replace HIV1549_r ="0.57" if CountryName == "Uruguay" & year ==2002
replace HIV1549_r ="0.59" if CountryName == "Estonia" & year ==2001
replace HIV1549_r ="0.61" if CountryName == "Panama" & year ==2003
replace HIV1549_r ="0.61" if CountryName == "Panama" & year ==2004
replace HIV1549_r ="0.61" if CountryName == "Panama" & year ==2005
replace HIV1549_r ="0.61" if CountryName == "Panama" & year ==2006
replace HIV1549_r ="0.62" if CountryName == "Panama" & year ==2002
replace HIV1549_r ="0.62" if CountryName == "Panama" & year ==2007
replace HIV1549_r ="0.62" if CountryName == "Panama" & year ==2008
replace HIV1549_r ="0.62" if CountryName == "Panama" & year ==2009
replace HIV1549_r ="0.63" if CountryName == "Panama" & year ==2001
replace HIV1549_r ="0.63" if CountryName == "Uruguay" & year ==2003
replace HIV1549_r ="0.63" if CountryName == "Panama" & year ==2010
replace HIV1549_r ="0.64" if CountryName == "Panama" & year ==1999
replace HIV1549_r ="0.64" if CountryName == "Panama" & year ==2000
replace HIV1549_r ="0.64" if CountryName == "Panama" & year ==2011
replace HIV1549_r ="0.64" if CountryName == "Sao Tome and Principe" & year ==2013
replace HIV1549_r ="0.65" if CountryName == "Sao Tome and Principe" & year ==1997
replace HIV1549_r ="0.65" if CountryName == "Panama" & year ==2012
replace HIV1549_r ="0.65" if CountryName == "Panama" & year ==2013
replace HIV1549_r ="0.66" if CountryName == "Panama" & year ==1998
replace HIV1549_r ="0.67" if CountryName == "Uruguay" & year ==2004
replace HIV1549_r ="0.69" if CountryName == "Panama" & year ==1997
replace HIV1549_r ="0.71" if CountryName == "Uruguay" & year ==2005
replace HIV1549_r ="0.71" if CountryName == "Uruguay" & year ==2011
replace HIV1549_r ="0.71" if CountryName == "Uruguay" & year ==2012
replace HIV1549_r ="0.71" if CountryName == "Uruguay" & year ==2013
replace HIV1549_r ="0.72" if CountryName == "Panama" & year ==1996
replace HIV1549_r ="0.72" if CountryName == "Estonia" & year ==2002
replace HIV1549_r ="0.72" if CountryName == "Uruguay" & year ==2010
replace HIV1549_r ="0.73" if CountryName == "Uruguay" & year ==2006
replace HIV1549_r ="0.73" if CountryName == "Uruguay" & year ==2009
replace HIV1549_r ="0.74" if CountryName == "Uruguay" & year ==2007
replace HIV1549_r ="0.74" if CountryName == "Uruguay" & year ==2008
replace HIV1549_r ="0.74" if CountryName == "Sao Tome and Principe" & year ==2012
replace HIV1549_r ="0.75" if CountryName == "Panama" & year ==1995
replace HIV1549_r ="0.75" if CountryName == "Belize" & year ==1997
replace HIV1549_r ="0.79" if CountryName == "Panama" & year ==1994
replace HIV1549_r ="0.80" if CountryName == "Sao Tome and Principe" & year ==1998
replace HIV1549_r ="0.84" if CountryName == "Panama" & year ==1993
replace HIV1549_r ="0.84" if CountryName == "Estonia" & year ==2003
replace HIV1549_r ="0.84" if CountryName == "Sao Tome and Principe" & year ==2011
replace HIV1549_r ="0.88" if CountryName == "Panama" & year ==1992
replace HIV1549_r ="0.93" if CountryName == "Estonia" & year ==2004
replace HIV1549_r ="0.94" if CountryName == "Panama" & year ==1991
replace HIV1549_r ="0.95" if CountryName == "Panama" & year ==1990
replace HIV1549_r ="0.96" if CountryName == "Sao Tome and Principe" & year ==1999
replace HIV1549_r ="0.96" if CountryName == "Sao Tome and Principe" & year ==2010
replace HIV1549_r ="1.01" if CountryName == "Estonia" & year ==2005
replace HIV1549_r ="1.07" if CountryName == "Estonia" & year ==2006
replace HIV1549_r ="1.08" if CountryName == "Sao Tome and Principe" & year ==2009
replace HIV1549_r ="1.11" if CountryName == "Sao Tome and Principe" & year ==2000
replace HIV1549_r ="1.12" if CountryName == "Estonia" & year ==2007
replace HIV1549_r ="1.15" if CountryName == "Estonia" & year ==2008
replace HIV1549_r ="1.16" if CountryName == "Belize" & year ==1998
replace HIV1549_r ="1.18" if CountryName == "Estonia" & year ==2009
replace HIV1549_r ="1.20" if CountryName == "Sao Tome and Principe" & year ==2008
replace HIV1549_r ="1.21" if CountryName == "Estonia" & year ==2010
replace HIV1549_r ="1.24" if CountryName == "Estonia" & year ==2011
replace HIV1549_r ="1.25" if CountryName == "Sao Tome and Principe" & year ==2001
replace HIV1549_r ="1.27" if CountryName == "Estonia" & year ==2012
replace HIV1549_r ="1.30" if CountryName == "Sao Tome and Principe" & year ==2007
replace HIV1549_r ="1.30" if CountryName == "Estonia" & year ==2013
replace HIV1549_r ="1.36" if CountryName == "Sao Tome and Principe" & year ==2002
replace HIV1549_r ="1.39" if CountryName == "Sao Tome and Principe" & year ==2006
replace HIV1549_r ="1.42" if CountryName == "Sao Tome and Principe" & year ==2003
replace HIV1549_r ="1.44" if CountryName == "Sao Tome and Principe" & year ==2005
replace HIV1549_r ="1.46" if CountryName == "Sao Tome and Principe" & year ==2004
replace HIV1549_r ="1.49" if CountryName == "Belize" & year ==2013
replace HIV1549_r ="1.51" if CountryName == "Belize" & year ==2012
replace HIV1549_r ="1.53" if CountryName == "Belize" & year ==2011
replace HIV1549_r ="1.54" if CountryName == "Belize" & year ==1999
replace HIV1549_r ="1.54" if CountryName == "Belize" & year ==2010
replace HIV1549_r ="1.58" if CountryName == "Belize" & year ==2009
replace HIV1549_r ="1.61" if CountryName == "Belize" & year ==2008
replace HIV1549_r ="1.62" if CountryName == "Belize" & year ==2007
replace HIV1549_r ="1.66" if CountryName == "Belize" & year ==2006
replace HIV1549_r ="1.71" if CountryName == "Belize" & year ==2005
replace HIV1549_r ="1.76" if CountryName == "Belize" & year ==2000
replace HIV1549_r ="1.76" if CountryName == "Belize" & year ==2004
replace HIV1549_r ="1.80" if CountryName == "Belize" & year ==2003
replace HIV1549_r ="1.84" if CountryName == "Belize" & year ==2001
replace HIV1549_r ="1.84" if CountryName == "Belize" & year ==2002
* same data source than for poverty
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore

preserve
* we combine WB data and data from http://mdgs.un.org/unsd/mdg/Data.aspx
import excel "$chemin\data\input\Data_Extract_From_World_Development_Indicators.xlsx", sheet("mater") firstrow clear
reshape long YR, i(Country*) j(year)
rename YR maternalmortality_r
merge 1:1 Country* year using temp
drop _m
save temp, replace
restore


use temp, clear
destring maternalmortality_r HIV1549- poverty, replace force
* we impute missing value by the last known value as we expect donor to allocate aid given the information (ie. the last known figures) and not some extrapolations.
sort Countr* year
foreach i of varlist maternalmortality_r HIV1549- poverty {
	sort CountryName year
	mipolate `i' year, gen(`i'n) nearest by(CountryName)
	drop `i'
	rename `i'n `i'
	mipolate `i' year, gen(`i'n) linear by(CountryName)
	drop `i'
	rename `i'n `i'
}

rename CountryName recipient_name
rename CountryCode recipient_code

replace recipient_name = "Yemen" if recipient_name == "Yemen, Rep."
replace recipient_name = "Venezuela" if recipient_name == "Venezuela, RB"
replace recipient_name = "The Gambia" if recipient_name == "Gambia, The"
replace recipient_name = "Syria" if recipient_name == "Syrian Arab Republic"
replace recipient_name = "Swaziland" if recipient_name == "Eswatini"
replace recipient_name = "Saint Vincent and the Grenadines" if recipient_name == "St. Vincent and the Grenadines"
replace recipient_name = "Saint Lucia" if recipient_name == "St. Lucia"
replace recipient_name = "Saint Kitts and Nevis" if recipient_name == "St. Kitts and Nevis"
replace recipient_name = "Russia" if recipient_name == "Russian Federation"
replace recipient_name = "Palestine" if recipient_name == "West Bank and Gaza"
replace recipient_name = "North Korea" if recipient_name == "Korea, Dem. People's Rep."
replace recipient_name = "Macedonia" if recipient_name == "North Macedonia"
replace recipient_name = "Laos" if recipient_name == "Lao PDR"
replace recipient_name = "Kyrgyzstan" if recipient_name == "Kyrgyz Republic"
replace recipient_name = "Iran" if recipient_name == "Iran, Islamic Rep."
replace recipient_name = "Egypt" if recipient_name == "Egypt, Arab Rep."
replace recipient_name = "Democratic Republic of the Congo" if recipient_name == "Congo, Dem. Rep."
replace recipient_name = "Congo" if recipient_name == "Congo, Rep."
replace recipient_name = "Cape Verde" if recipient_name == "Cabo Verde"
replace recipient_name = "Federated States of Micronesia" if recipient_name == "Micronesia, Fed. Sts."
replace recipient_name = "Korea, Rep." if recipient_name =="South Korea"

save "$chemin\data\controls_rt.dta", replace

erase temp.dta



* merge table aid and controls ***
use final_IHME22, clear
rename recipient_country recipient_name
rename source donor
merge n:1 recipient_name year using controls_rt

drop if _m == 2
drop _m
save final_IHME22, replace



* Add Polity4
* download from https://www.systemicpeace.org/inscrdata.html 01/12/2022
import excel "$chemin\data\input\p5v2018.xls", sheet("p5v2018") firstrow clear
rename country recipient_name
keep year recipient_name polity2
keep if year >1989 
replace recipient_name = "Timor-Leste" if recipient_name == "Timor Leste"
replace recipient_name = "The Gambia" if recipient_name == ""
replace recipient_name = "Sudan" if recipient_name == "Sudan-North"
replace recipient_name = "South Korea" if recipient_name == "Korea South"
replace recipient_name = "North Korea" if recipient_name == "Korea North"
replace recipient_name = "Myanmar" if recipient_name == "Myanmar (Burma)"
replace recipient_name = "Democratic Republic of the Congo" if recipient_name == "Congo Kinshasa"
replace recipient_name = "Congo" if recipient_name == "Congo Brazzaville"
replace recipient_name = "Bosnia and Herzegovina" if recipient_name == "Bosnia"
replace recipient_name = "Serbia" if recipient_name == "Serbia and Montenegro"
replace recipient_name = "Cote d'Ivoire" if recipient_name == "Ivory Coast"
replace recipient_name = "Cote d'Ivoire" if recipient_name == "Cote D'Ivoire"

foreach i of numlist 1990/2001 {
expand 2 if recipient_name == "Indonesia" & year == `i'
sort recipient_name year	
bys recipient_name year : replace recipient_name = "Timor-Leste" if recipient_name == "Indonesia"  & year == `i' & _n == 1
}

duplicates drop year rec, force
merge 1:n recipient_name year using final_IHME22
drop if _m == 1
drop _m 
save final_IHME22, replace

* add ideal distance (UN proximity controls)
import delimited "$chemin\data\input\IdealpointestimatesAll_Jun2022.csv", clear 
keep countr ccode
rename cc ccode1
rename countryname donor
duplicates drop *, force 
save temp2, replace

import delimited "$chemin\data\input\AgreementScoresAll_Jun2022.csv", clear 
merge n:1 ccode1 using temp2
drop _m
save temp3, replace
use temp2, clear
rename cc ccode2
rename donor recipient_name
save temp2, replace 
use temp3, clear 
merge n:1 ccode2 using temp2
drop _m
keep idealpointdistance  donor recipient_name year
replace recipient_name = "Antigua and Barbuda" if recipient_name == "Antigua & Barbuda"
replace recipient_name = "Cote d'Ivoire" if recipient_name == "Côte dIvoire"
replace recipient_name = "Saint Vincent and the Grenadines" if recipient_name == "St. Vincent & Grenadines"
replace recipient_name = "Saint Lucia" if recipient_name == "St. Lucia"
replace recipient_name = "Saint Kitts and Nevis" if recipient_name == "St. Kitts & Nevis"
replace recipient_name = "The Gambia" if recipient_name == "Gambia"
replace recipient_name = "Yemen" if recipient_name == "Yemen Arab Republic"
replace recipient_name = "Trinidad and Tobago" if recipient_name == "Trinidad & Tobago"
replace recipient_name = "Swaziland" if recipient_name == "Eswatini"
replace recipient_name = "Serbia" if recipient_name == "Yugoslavia"
replace recipient_name = "Myanmar" if recipient_name == "Myanmar (Burma)"
replace recipient_name = "Federated States of Micronesia" if recipient_name == "Micronesia (Federated States of)"
replace recipient_name = "Cote d'Ivoire" if recipient_name == ""
replace recipient_name = "Congo" if recipient_name == "Congo - Brazzaville"
replace recipient_name = "Democratic Republic of the Congo" if recipient_name == "Congo - Kinshasa"
replace recipient_name = "Bosnia and Herzegovina" if recipient_name == "Bosnia & Herzegovina"
replace recipient_name = "Sao Tome and Principe" if recipient_name == "São Tomé & Príncipe"

replace donor = "United_Kingdom" if donor == "United Kingdom"
replace donor = "New_Zealand" if donor == "New Zealand"
replace donor = "Korea" if donor == "South Korea"
replace donor = "Germany" if donor == "German Federal Republic"
keep if year >1989



merge 1:1 year donor recipient_name using final_IHME22
drop if _m ==1
drop _m
rename idealpointdistance UN_dr
destring UN_dr, replace force
save final_IHME22, replace

use temp3, clear 
merge n:1 ccode2 using temp2
keep if recipient_name == "United States"
keep donor year agree
rename agree pctagreeus
replace donor = "United_Kingdom" if donor == "United Kingdom"
replace donor = "New_Zealand" if donor == "New Zealand"
replace donor = "Korea" if donor == "South Korea"
replace donor = "Germany" if donor == "German Federal Republic"
duplicates drop * , force
merge 1:n year donor  using final_IHME22
drop if _m == 1
drop _m

foreach i of varlist polity2 *_r share*   {
	sort recipient_name year
	mipolate `i' year, gen(`i'n) nearest by(recipient_name)
	drop `i'
	rename `i'n `i'
	mipolate `i' year, gen(`i'n) linear by(recipient_name)
	drop `i'
	rename `i'n `i'
}


gsort recipient_name -wb_regioncode
bys recipient_name : replace wb_regioncode = wb_regioncode[_n-1] if wb_regioncode == "" & wb_regioncode[_n-1] != ""

gsort recipient_name -wb_location_id
bys recipient_name : replace wb_location_id = wb_location_id[_n-1] if wb_location_id == . & wb_location_id[_n-1] != .

gsort recipient_name year usshare
bys recipient_name year : replace usshare = usshare[_n-1] if usshare == . & usshare[_n-1] != .

sort recipient_name sharenonbil_donor
bys recipient_name : replace sharenonbil_donor = sharenonbil_donor[_n-1] if sharenonbil_donor == . & sharenonbil_donor[_n-1] != .

foreach i of varlist *rmh* unalloc* sharenonbil sharengo {
replace `i' = 0 if `i' == .
}

codebook recipient_c

save final_IHME22, replace

* data on trade download manualy from https://comtrade.un.org/data/ 30/11/2022
import delimited "$chemin\data\input\comtrade_07.csv", clear
save U, replace
foreach i of numlist 0/5 {
		foreach j of numlist 1/7 {
				import delimited "$chemin\data\input\comtrade_`i'`j'.csv", clear
				append using U, force
		save U, replace
		}
		
}
 keep year reporter reporteriso partner partneriso tradevalueus
 replace reporter = "Korea" if reporter == "Rep. of Korea"
 replace reporter = "European Union" if reporter == "EU"
 rename reporter donor
 rename partner recipient_name
 drop if donor == "" & recipient_name == "" 
 replace recipient_name = "Vietnam" if recipient_name == "Viet Nam"
 replace recipient_name = "Tanzania" if recipient_name == "United Rep. of Tanzania"
 replace recipient_name = "Turks and Caicos Isdlands" if recipient_name == "Turks and Caicos Isds"
 replace recipient_name = "Wallis and Futuna Islands" if recipient_name == "Wallis and Futuna Isds"
 replace recipient_name = "Swaziland" if recipient_name == "Eswatini"
 replace recipient_name = "Palestine" if recipient_name == "State of BunkersPalestine"
 replace recipient_name = "Solomon Islands" if recipient_name == "Solomon Isds"
 replace recipient_name = "Russia" if recipient_name == "Russian Federation"
 replace recipient_name = "Moldova" if recipient_name == "Rep. of Moldova"
 replace recipient_name = "Netherlands Antilles" if recipient_name == "Neth. Antilles"
 replace recipient_name = "Northern Mariana Islands" if recipient_name == "N. Mariana Isds"
 replace recipient_name = "Marshall Islands" if recipient_name == "Marshall Isds"
 replace recipient_name = "Laos" if recipient_name == "Lao People's Dem. Rep."
 replace recipient_name = "The Gambia" if recipient_name == "Gambia"
 replace recipient_name = "Federated States of Micronesia" if recipient_name == "FS Micronesia"
 replace recipient_name = "Dominican Republic" if recipient_name == "Dominican Rep."
 replace recipient_name = "Cote d'Ivoire" if recipient_name == "CÃ´te d'Ivoire"
 replace recipient_name = "Democratic Republic of the Congo" if recipient_name == "Dem. Rep. of the Congo"
 replace recipient_name = "North Korea" if recipient_name == "Dem. People's Rep. of Korea"
 replace recipient_name = "Cook Islands" if recipient_name == "Cook Isds"
 replace recipient_name = "Central African Republic" if recipient_name == "Central African Rep."
 replace recipient_name = "Cape Verde" if recipient_name == "Cabo Verde"
 replace recipient_name = "Bosnia and Herzegovina" if recipient_name == "Bosnia Herzegovina"
 replace recipient_name = "Bolivia" if recipient_name == "Bolivia (Plurinational State of)"
 replace recipient_name = "South Korea" if recipient_name == "Rep. of Korea"
 replace donor = "United_Kingdom" if donor == "United Kingdom"
 replace donor = "New_Zealand" if donor == "New Zealand"
 drop if recipient_name == "World"
 drop if recipient_name == "United States Minor Outlying Islands"
 drop if recipient_name == "US Misc. Pacific Isds"
 drop if recipient_name == "Special Categories"
 drop if recipient_name == "So. African Customs Union"
 drop if recipient_name == "Rest of America, nes"
 drop if strpos(recipient_name,"Other")>0
 drop if recipient_name == "LAIA, nes"
 drop if recipient_name == "Free Zones"
 drop if recipient_name == "Europe EU, nes"
 drop if recipient_name == "Caribbean, nes"
 drop if recipient_name == "Bunkers"
 drop if recipient_name == "Areas, nes"
 * compute share of export for each donor
 
 bys recipient year : egen a = total(tradevalueus) if donor == "USA"
 bys recipient year : egen exportUS = min(a)
 replace exportUS = 0 if exportUS == .
 
 save U, replace
 
 use U, clear
 merge 1:1 donor recipient_name year using final_IHME22

  replace exportUS = 0 if exportUS == .
replace tradevalueus = 0 if tradevalueus == .
 gen economiccompetition = min(tradevalueus,exportUS)/max(tradevalueus,exportUS)
bys recipient_name donor : egen economiccompetition_max = max(economiccompetition)
bys recipient_name donor : egen economiccompetition_mean = mean(economiccompetition)
 keep if _m >=2
 drop _m
  * add information on abortion laws in recipient and donor country.

		gen abortion=.
 			replace abortion = 1 if recipient_name =="Congo"
			replace abortion = 1 if recipient_name =="Dominican Republic"
			replace abortion = 1 if recipient_name =="Egypt"
			replace abortion = 1 if recipient_name =="El Salvador"
			replace abortion = 1 if recipient_name =="Haiti"
			replace abortion = 1 if recipient_name =="Honduras"
			replace abortion = 1 if recipient_name =="Iraq"
			replace abortion = 1 if recipient_name =="Jamaica"
			replace abortion = 1 if recipient_name =="Laos"
			replace abortion = 1 if recipient_name =="Madagascar"
			replace abortion = 1 if recipient_name =="Malta"
			replace abortion = 1 if recipient_name =="Mauritania"
			replace abortion = 1 if recipient_name =="Nicaragua"
			replace abortion = 1 if recipient_name =="Palau"
			replace abortion = 1 if recipient_name =="Palestine"
			replace abortion = 1 if recipient_name =="Philippines"
			replace abortion = 1 if recipient_name =="Senegal"
			replace abortion = 1 if recipient_name =="Sierra Leone"
			replace abortion = 1 if recipient_name =="Suriname"
			replace abortion = 1 if recipient_name =="Tonga"

			replace abortion = 2 if recipient_name =="Afghanistan"
			replace abortion = 2 if recipient_name =="Antigua and Barbuda"
			replace abortion = 2 if recipient_name =="Bahrain"
			replace abortion = 2 if recipient_name =="Bangladesh"
			replace abortion = 2 if recipient_name =="Bhutan" 
			replace abortion = 2 if recipient_name =="Brazil"
			replace abortion = 2 if recipient_name =="Chile" 
			replace abortion = 2 if recipient_name =="Cote d'Ivoire"
			replace abortion = 2 if recipient_name =="Dominica"
			replace abortion = 2 if recipient_name =="Federated States of Micronesia" 
			replace abortion = 2 if recipient_name =="Gabon"
			replace abortion = 2 if recipient_name =="Guatemala"
			replace abortion = 2 if recipient_name =="Indonesia"
			replace abortion = 2 if recipient_name =="Iran" 
			replace abortion = 2 if recipient_name =="Kiribati"
			replace abortion = 2 if recipient_name =="Lebanon"
			replace abortion = 2 if recipient_name =="Libya"
			replace abortion = 2 if recipient_name =="Malawi"
			replace abortion = 2 if recipient_name =="Mali"
			replace abortion = 2 if recipient_name =="Marshall Islands"
			replace abortion = 2 if recipient_name =="Mexico"
			replace abortion = 2 if recipient_name =="Myanmar"
			replace abortion = 2 if recipient_name =="Nigeria"
			replace abortion = 2 if recipient_name =="Oman"
			replace abortion = 2 if recipient_name =="Panama"
			replace abortion = 2 if recipient_name =="Papua New Guinea"
			replace abortion = 2 if recipient_name =="Paraguay"
			replace abortion = 2 if recipient_name =="Solomon Islands"
			replace abortion = 2 if recipient_name =="Somalia" 
			replace abortion = 2 if recipient_name =="South Sudan"
			replace abortion = 2 if recipient_name =="Sri Lanka"
			replace abortion = 2 if recipient_name =="Sudan"
			replace abortion = 2 if recipient_name =="Syria"
			replace abortion = 2 if recipient_name =="Tanzania"
			replace abortion = 2 if recipient_name =="The Gambia"
			replace abortion = 2 if recipient_name =="Timor-Leste"
			replace abortion = 2 if recipient_name =="Tuvalu"
			replace abortion = 2 if recipient_name =="Uganda"
			replace abortion = 2 if recipient_name =="Venezuela"
			replace abortion = 2 if recipient_name =="Yemen"

			replace abortion = 3 if recipient_name =="Algeria"
			replace abortion = 3 if recipient_name =="Angola" 
			replace abortion = 3 if recipient_name =="Benin"
			replace abortion = 3 if recipient_name =="Bolivia"
			replace abortion = 3 if recipient_name =="Botswana"
			replace abortion = 3 if recipient_name =="Burkina Faso" 
			replace abortion = 3 if recipient_name =="Burundi"
			replace abortion = 3 if recipient_name =="Cameroon"
			replace abortion = 3 if recipient_name =="Central African Republic" 
			replace abortion = 3 if recipient_name =="Chad" 
			replace abortion = 3 if recipient_name =="Colombia" 
			replace abortion = 3 if recipient_name =="Comoros"
			replace abortion = 3 if recipient_name =="Costa Rica"
			replace abortion = 3 if recipient_name =="Democratic Republic of the Congo" 
			replace abortion = 3 if recipient_name =="Djibouti"
			replace abortion = 3 if recipient_name =="Ecuador"
			replace abortion = 3 if recipient_name =="Equatorial Guinea"
			replace abortion = 3 if recipient_name =="Eritrea"
			replace abortion = 3 if recipient_name =="Ghana"
			replace abortion = 3 if recipient_name =="Grenada"
			replace abortion = 3 if recipient_name =="Guinea"
			replace abortion = 3 if recipient_name =="Jordan"
			replace abortion = 3 if recipient_name =="Kenya"
			replace abortion = 3 if recipient_name =="Lesotho" 
			replace abortion = 3 if recipient_name =="Liberia"
			replace abortion = 3 if recipient_name =="Malaysia"
			replace abortion = 3 if recipient_name =="Mauritius" 
			replace abortion = 3 if recipient_name =="Morocco"
			replace abortion = 3 if recipient_name =="Namibia"
			replace abortion = 3 if recipient_name =="Nauru"
			replace abortion = 3 if recipient_name =="Niger" 
			replace abortion = 3 if recipient_name =="Pakistan"
			replace abortion = 3 if recipient_name =="Peru"
			replace abortion = 3 if recipient_name =="Poland"
			replace abortion = 3 if recipient_name =="Saint Kitts and Nevis"
			replace abortion = 3 if recipient_name =="Saint Lucia"
			replace abortion = 3 if recipient_name =="Samoa"
			replace abortion = 3 if recipient_name =="Saudi Arabia"
			replace abortion = 3 if recipient_name =="Seychelles"
			replace abortion = 3 if recipient_name =="South Korea"
			replace abortion = 3 if recipient_name =="Swaziland" 
			replace abortion = 3 if recipient_name =="Togo" 
			replace abortion = 3 if recipient_name =="Trinidad and Tobago"
			replace abortion = 3 if recipient_name =="Vanuatu"
			replace abortion = 3 if recipient_name =="Zimbabwe"


			replace abortion = 4 if recipient_name =="Barbados"
			replace abortion = 4 if recipient_name =="Belize"
			replace abortion = 4 if recipient_name =="Ethiopia" 
			replace abortion = 4 if recipient_name =="Fiji"
			replace abortion = 4 if recipient_name =="India"
			replace abortion = 4 if recipient_name =="Rwanda" 
			replace abortion = 4 if recipient_name =="Saint Vincent and the Grenadines"
			replace abortion = 4 if recipient_name =="Zambia"


			replace abortion = 5 if recipient_name =="Albania" 
			replace abortion = 5 if recipient_name =="Argentina"
			replace abortion = 5 if recipient_name =="Armenia"
			replace abortion = 5 if recipient_name =="Azerbaijan"
			replace abortion = 5 if recipient_name =="Belarus"
			replace abortion = 5 if recipient_name =="Bosnia and Herzegovina"
			replace abortion = 5 if recipient_name =="Bulgaria"
			replace abortion = 5 if recipient_name =="Cambodia" 
			replace abortion = 5 if recipient_name =="Cape Verde"
			replace abortion = 5 if recipient_name =="China"
			replace abortion = 5 if recipient_name =="Croatia"
			replace abortion = 5 if recipient_name =="Cuba"
			replace abortion = 5 if recipient_name =="Estonia"
			replace abortion = 5 if recipient_name =="Georgia"
			replace abortion = 5 if recipient_name =="Guinea-Bissau"
			replace abortion = 5 if recipient_name =="Guyana" 
			replace abortion = 5 if recipient_name =="Hungary"
			replace abortion = 5 if recipient_name =="Kazakhstan"
			replace abortion = 5 if recipient_name =="Kyrgyzstan"
			replace abortion = 5 if recipient_name =="Latvia"
			replace abortion = 5 if recipient_name =="Lithuania"
			replace abortion = 5 if recipient_name =="Maldives"
			replace abortion = 5 if recipient_name =="Mayotte"
			replace abortion = 5 if recipient_name =="Moldova"
			replace abortion = 5 if recipient_name =="Mongolia"
			replace abortion = 5 if recipient_name =="Montenegro"
			replace abortion = 5 if recipient_name =="Mozambique" 
			replace abortion = 5 if recipient_name =="Nepal" 
			replace abortion = 5 if recipient_name =="Netherlands Antilles"
			replace abortion = 5 if recipient_name =="North Macedonia"
			replace abortion = 5 if recipient_name =="Romania"
			replace abortion = 5 if recipient_name =="Russia"
			replace abortion = 5 if recipient_name =="Sao Tome and Principe"
			replace abortion = 5 if recipient_name =="Serbia"
			replace abortion = 5 if recipient_name =="Slovenia"
			replace abortion = 5 if recipient_name =="South Africa"
			replace abortion = 5 if recipient_name =="Tajikistan"
			replace abortion = 5 if recipient_name =="Thailand"
			replace abortion = 5 if recipient_name =="Tunisia"
			replace abortion = 5 if recipient_name =="Turkey"
			replace abortion = 5 if recipient_name =="Turkmenistan"
			replace abortion = 5 if recipient_name =="Ukraine"
			replace abortion = 5 if recipient_name =="Uruguay" 
			replace abortion = 5 if recipient_name =="Uzbekistan"
			replace abortion = 5 if recipient_name =="Vietnam"
			replace abortion = 5 if recipient_name =="Wallis and Futuna Islands"
			replace abortion = . if recipient_name =="Anguilla"
			replace abortion = . if recipient_name =="Cook Islands"
			replace abortion = . if recipient_name =="Montserrat"
			replace abortion = . if recipient_name =="Niue"
			replace abortion = . if recipient_name =="North Korea"
			replace abortion = . if recipient_name =="Northern Mariana Islands"
			replace abortion = . if recipient_name =="Saint Helena"
			replace abortion = . if recipient_name =="Tokelau"
			replace abortion = . if recipient_name =="Turks and Caicos Islands"
			gen abortionsimple = (abortion >= 5)
			replace abortionsimple = . if abortion == .

			* source https://abortion-policies.srhr.org/ : sum of AT women's request and can the woman or girl be sanctioned (2 yes/no, 0 No/Yes, 1 Yes/Yes or No/No)
			gen abortiondonor = .
			replace abortiondonor = 1 if donor == "France"
			replace abortiondonor = 0 if donor == "Australia"
			replace abortiondonor = 0 if donor == "Austria"
			replace abortiondonor = 1 if donor == "Belgium"
			replace abortiondonor = 1 if donor == "China"
			replace abortiondonor = 1 if donor == "Denmark"
			replace abortiondonor = 0 if donor == "Finland"
			replace abortiondonor = 0 if donor == "Germany"
			replace abortiondonor = 0 if donor == "Ireland"
			replace abortiondonor = 0 if donor == "Italy"
			replace abortiondonor = 0 if donor == "Japan"
			replace abortiondonor = 0 if donor == "Korea"
			replace abortiondonor = 0 if donor == "Switzerland"
			replace abortiondonor = 1 if donor == "Sweden"
			replace abortiondonor = 0 if donor == "United_Kingdom"
			replace abortiondonor = 0 if donor == "Luxembourg"
			replace abortiondonor = 1 if donor == "Netherlands"
			replace abortiondonor = 0 if donor == "New_Zealand"
			replace abortiondonor = 1 if donor == "Norway"
			replace abortiondonor = 0 if donor == "Portugal"
			replace abortiondonor = 0 if donor == "Spain"
			replace abortiondonor = 0 if donor == "Greece"
			replace abortiondonor = 1 if donor == "Canada"
			replace abortiondonor = 0 if donor == "BMGF" /*https://wng.org/sift/melinda-gates-abortion-is-not-womens-healthcare-1617422262*/
			replace abortiondonor = 0 if donor == "European Union"
			
 save final_IHME22, replace
erase a2.dta
erase controls_rt.dta
erase data.dta
erase data2.dta
erase fill2.dta
erase temp2.dta
erase temp3.dta
erase U.dta